package com.ruoyi.web.controller.house;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house.domain.WebmagicBuildingSale;
import com.ruoyi.house.service.IWebmagicBuildingSaleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼宇售卖Controller
 * 
 * @author ruoyi
 * @date 2023-06-09
 */
@Controller
@RequestMapping("/house/sale")
public class WebmagicBuildingSaleController extends BaseController
{
    private String prefix = "house/sale";

    @Autowired
    private IWebmagicBuildingSaleService webmagicBuildingSaleService;

    @RequiresPermissions("house:sale:view")
    @GetMapping()
    public String sale()
    {
        return prefix + "/sale";
    }

    /**
     * 查询楼宇售卖列表
     */
    @RequiresPermissions("house:sale:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebmagicBuildingSale webmagicBuildingSale)
    {
        startPage();
        List<WebmagicBuildingSale> list = webmagicBuildingSaleService.selectWebmagicBuildingSaleList(webmagicBuildingSale);
        return getDataTable(list);
    }

    /**
     * 导出楼宇售卖列表
     */
    @RequiresPermissions("house:sale:export")
    @Log(title = "楼宇售卖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebmagicBuildingSale webmagicBuildingSale)
    {
        List<WebmagicBuildingSale> list = webmagicBuildingSaleService.selectWebmagicBuildingSaleList(webmagicBuildingSale);
        ExcelUtil<WebmagicBuildingSale> util = new ExcelUtil<WebmagicBuildingSale>(WebmagicBuildingSale.class);
        return util.exportExcel(list, "楼宇售卖数据");
    }

    /**
     * 新增楼宇售卖
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存楼宇售卖
     */
    @RequiresPermissions("house:sale:add")
    @Log(title = "楼宇售卖", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebmagicBuildingSale webmagicBuildingSale)
    {
        return toAjax(webmagicBuildingSaleService.insertWebmagicBuildingSale(webmagicBuildingSale));
    }

    /**
     * 修改楼宇售卖
     */
    @RequiresPermissions("house:sale:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WebmagicBuildingSale webmagicBuildingSale = webmagicBuildingSaleService.selectWebmagicBuildingSaleById(id);
        mmap.put("webmagicBuildingSale", webmagicBuildingSale);
        return prefix + "/edit";
    }

    /**
     * 修改保存楼宇售卖
     */
    @RequiresPermissions("house:sale:edit")
    @Log(title = "楼宇售卖", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebmagicBuildingSale webmagicBuildingSale)
    {
        return toAjax(webmagicBuildingSaleService.updateWebmagicBuildingSale(webmagicBuildingSale));
    }

    /**
     * 删除楼宇售卖
     */
    @RequiresPermissions("house:sale:remove")
    @Log(title = "楼宇售卖", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(webmagicBuildingSaleService.deleteWebmagicBuildingSaleByIds(ids));
    }
}
